home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Frameworks / Extension Shell 1.3 / Extension Shell 1.3 (Source) / RESP.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-06  |  3.4 KB  |  112 lines  |  [TEXT/R*ch]

  1. /*    NAME:
  2.         RESP.c
  3.  
  4.     WRITTEN BY:
  5.         Joe Holt (from the Usenet Macintosh Programmer's Guide).
  6.     
  7.     MODIFIED BY:
  8.         Dair Grant
  9.                 
  10.     DESCRIPTION:
  11.         This file contains a 'RESP' code resource. It's job is to unload a
  12.         Notification Manager request from memory, and then dispose of itself.
  13.  
  14.     NOTES:
  15.         •    Compiled with THINK C 6.0.
  16.  
  17.         •    This code resource is generic and can be pasted into any INIT that
  18.             uses the NotifyMsg.c code.
  19.  
  20.     ___________________________________________________________________________
  21.  
  22.     VERSION HISTORY:
  23.         (June 1990, jhh)
  24.             •    Response to Usenet news posting. Archived in Usenet Macintosh
  25.                 Programmer's Guide.
  26.  
  27.         (Oct 1993, dg)
  28.             •    Added call to _FlushInstructionCache and __FlushDataCache.
  29.                 Otherwise, the code fell over on 040s.
  30.  
  31.         (Jan 1994, dg)
  32.             •    Changed type and ID of Resp code for use with Extension Shell.
  33.             
  34.             
  35.     ___________________________________________________________________________
  36. */
  37. //=============================================================================
  38. //        Function prototypes                                                                     
  39. //-----------------------------------------------------------------------------
  40. pascal void    main(QElemPtr nmReqPtr);
  41.  
  42.  
  43.  
  44.  
  45.  
  46. //=============================================================================
  47. //        Global variables                                                                 
  48. //-----------------------------------------------------------------------------
  49. extern long    ToolScratch : 0x09CE;        // ToolScratch is an 8 byte low-memory
  50.                                         // global used as a temporary holding
  51.                                         // place.
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. //=============================================================================
  63. //        main : Entry point to our 'RESP' code resource.                                                                 
  64. //-----------------------------------------------------------------------------
  65. //        Note :    This code is called when the user closes the Notification
  66. //                Manager's dialog. The NM passes to us the address of the NM
  67. //                record which was set up by NotifyMsg.c. We dispose of the
  68. //                record, and then ourselves.
  69. //
  70. //                This is written in assembly for size. If you have problems
  71. //                with assembly, I s'pose it could be written in C, but the trick
  72. //                at the end would be hard to duplicate...
  73. //-----------------------------------------------------------------------------
  74. pascal void main(QElemPtr nmReqPtr)
  75. {
  76.     asm {
  77.             // First remove the note from the Notification Manager's
  78.             // Notification queue.
  79.             move.l        nmReqPtr, A0
  80.             _NMRemove
  81.  
  82.  
  83.             // Grab the string's address from the NM record and dispose
  84.             // of it. Then get rid of the NM record itself.
  85.             // Notification queue.
  86.             move.l        nmReqPtr, A0
  87.             move.l        OFFSET(NMRec,nmStr)(A0), A0
  88.             _DisposPtr
  89.             move.l        nmReqPtr, A0
  90.             _DisposPtr
  91.  
  92.  
  93.             // Now the tricky part. This code lives within a small block
  94.             // in the System Heap which we want to get rid of. But it's
  95.             // not safe to dispose of the very block you're calling from.
  96.             // So, we create a little bit of code in ToolScratch which
  97.             // does the dispose for us, and execute it last.
  98.             //
  99.             //    dg    - Added call to _FlushInstructionCache for 040s.
  100.             //            - Added call to _FlushDataCache for 040s.
  101.             move.l        4(A7), A1
  102.             move.l        #ToolScratch, A0
  103.             move.l        A0, 4(A7)
  104.             move.l        #0x2040A01F, (A0)                ; movea.l D0, A0 / _DisposPtr
  105.             move.w        #0x4ED1, 4(A0)                    ; jmp (A1)
  106.             jsr            FlushDataCache(A4)                ; flush the cache for 040s
  107.             jsr            FlushInstructionCache(A4)        ; flush the cache for 040s
  108.             lea            main, A0
  109.             move.l        A0, D0                            ; Pascal clobbers A0 on exit
  110.     }
  111. }
  112.